package Students

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/Students"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
    StudentsReq "github.com/flipped-aurora/gin-vue-admin/server/model/Students/request"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/service"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)

type Student_structApi struct {
}

var student_miniService = service.ServiceGroupApp.StudentsServiceGroup.Student_structService


// CreateStudent_struct 创建Student_struct
// @Tags Student_struct
// @Summary 创建Student_struct
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body Students.Student_struct true "创建Student_struct"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /student_mini/createStudent_struct [post]
func (student_miniApi *Student_structApi) CreateStudent_struct(c *gin.Context) {
	var student_mini Students.Student_struct
	err := c.ShouldBindJSON(&student_mini)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := student_miniService.CreateStudent_struct(&student_mini); err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteStudent_struct 删除Student_struct
// @Tags Student_struct
// @Summary 删除Student_struct
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body Students.Student_struct true "删除Student_struct"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /student_mini/deleteStudent_struct [delete]
func (student_miniApi *Student_structApi) DeleteStudent_struct(c *gin.Context) {
	var student_mini Students.Student_struct
	err := c.ShouldBindJSON(&student_mini)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := student_miniService.DeleteStudent_struct(student_mini); err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteStudent_structByIds 批量删除Student_struct
// @Tags Student_struct
// @Summary 批量删除Student_struct
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除Student_struct"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /student_mini/deleteStudent_structByIds [delete]
func (student_miniApi *Student_structApi) DeleteStudent_structByIds(c *gin.Context) {
	var IDS request.IdsReq
    err := c.ShouldBindJSON(&IDS)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := student_miniService.DeleteStudent_structByIds(IDS); err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateStudent_struct 更新Student_struct
// @Tags Student_struct
// @Summary 更新Student_struct
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body Students.Student_struct true "更新Student_struct"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /student_mini/updateStudent_struct [put]
func (student_miniApi *Student_structApi) UpdateStudent_struct(c *gin.Context) {
	var student_mini Students.Student_struct
	err := c.ShouldBindJSON(&student_mini)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := student_miniService.UpdateStudent_struct(student_mini); err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindStudent_struct 用id查询Student_struct
// @Tags Student_struct
// @Summary 用id查询Student_struct
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query Students.Student_struct true "用id查询Student_struct"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /student_mini/findStudent_struct [get]
func (student_miniApi *Student_structApi) FindStudent_struct(c *gin.Context) {
	var student_mini Students.Student_struct
	err := c.ShouldBindQuery(&student_mini)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if restudent_mini, err := student_miniService.GetStudent_struct(student_mini.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"restudent_mini": restudent_mini}, c)
	}
}

// GetStudent_structList 分页获取Student_struct列表
// @Tags Student_struct
// @Summary 分页获取Student_struct列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query StudentsReq.Student_structSearch true "分页获取Student_struct列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /student_mini/getStudent_structList [get]
func (student_miniApi *Student_structApi) GetStudent_structList(c *gin.Context) {
	var pageInfo StudentsReq.Student_structSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}

	// println("API:getStudent_structList pageInfo",pageInfo)
	
	if list, total, err := student_miniService.GetStudent_structInfoList(pageInfo); err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败", c)
    } else {
        response.OkWithDetailed(response.PageResult{
            List:     list,
            Total:    total,
            Page:     pageInfo.Page,
            PageSize: pageInfo.PageSize,
        }, "获取成功", c)
    }
}
